using Microsoft.Xna.Framework;


namespace LoD.WPClientLibrary.MapEngine {
    public class ViewPort {
        private Vector2 _location = Vector2.Zero;

        public ViewPort(int viewWidth, int viewHeight, int worldWidth, int worldHeight, Vector2 displayOffset) {
            this.ViewWidth = viewWidth;
            this.ViewHeight = viewHeight;
            this.WorldWidth = worldWidth;
            this.WorldHeight = worldHeight;
            this.DisplayOffset = displayOffset;
        }

        public int ViewWidth { get; private set; }
        public int ViewHeight { get; private set; }
        public int WorldWidth { get; private set; }
        public int WorldHeight { get; private set; }
        public Vector2 DisplayOffset { get; private set; }

        public Vector2 Location {
            get { return this._location; }
            set {
                this._location = new Vector2(
                    MathHelper.Clamp(value.X, 0f, this.WorldWidth - this.ViewWidth),
                    MathHelper.Clamp(value.Y, 0f, this.WorldHeight - this.ViewHeight));
            }
        }

        public Vector2 WorldToScreen(Vector2 worldPosition) { return worldPosition - this.Location + this.DisplayOffset; }

        public Vector2 ScreenToWorld(Vector2 screenPosition) { return screenPosition + this.Location - this.DisplayOffset; }

        public void Move(Vector2 offset) { this.Location += offset; }
    }
}